<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="format-detection" content="telephone=no">
    <meta name="msapplication-tap-highlight" content="no">
    <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">
    <title>文章审核/评论审核/反馈</title>
    <link rel='stylesheet' href='<%- rootUrl %>/res/adapter.css' />
    <link rel='stylesheet' href='<%- rootUrl %>/node_modules/font-awesome/css/font-awesome.min.css' />
    <style>
        a {text-decoration:none;cursor:pointer;color:unset}
        a:hover {text-decoration:underline;}
        .fa {cursor:unset}
        .article-list { padding:0 12px 12px 0 }
        .article-list > div:first-child b, .appends-list > div:first-child b {color:#152138}
        .article-list > div { border-bottom:1px solid gainsboro;padding:12px 0;margin:0 12px }
        .article-list > div:first-child, .article-list > div:last-child { border-bottom:0 }
        .article-list > div > p:first-child {color:darkgrey;font-size:11px}
        .article-list > div > p:nth-child(2) {color:black;font-size:16px}
        .article-list > div > p:last-child  { color:dimgrey;font-size:13px }
        .article-list > div > p button { background-image:none; background-color:transparent; border-width:0 }
        .appends-list { border:1px solid gainsboro }
        .appends-list > div { padding:9px 12px }
        .appends-list > div:not(:first-child) {font-size:15px;text-indent:0.5em}
    </style>
    <script src="<%- rootUrl %>/node_modules/jquery/dist/jquery.min.js"></script>
    <script src="<%- rootUrl %>/res/adapter.js"></script>
    <script src="<%- rootUrl %>/node_modules/socket.io-client/dist/socket.io.js"></script>
</head>
<body class="body-nomargin">
<alljs-widget><message-top><%- message %></message-top><user><%- username_uniq %></user></alljs-widget>
<%- components['signhead'] ? include(components['signhead'], this) : '' %>
<div class="width-limit article-list" style="padding-top:12px">
    <div><b><i class="fa fa-bars"></i>&nbsp;审核列表</b><span style="margin-left:0.5em;font-size:0.8em"><input type="checkbox" value="article" checked />文章&nbsp;<input type="checkbox" value="comment" checked />评论&nbsp;<input type="checkbox" value="feedback" checked />反馈</div>
    <% for (let audit of audits){ %>
    <div>
        <p><span class="time-span"><%- audit.produceTime %></span>&emsp;<a href="./user?id=<%- audit.produceUser._id %>"><%- audit.produceUser.nickname+'('+audit.produceUser._id+')' %></a>&emsp;发布/编辑的&nbsp;<%- typemap[audit.type] %></p>
        <p><%- audit.brief %></p>
        <p class="adapt-panel"><a href="/<%- audit.produceArticle.mainclass %>/article?id=<%- audit.produceArticle._id %>&path=<%- audit.path %>" style="flex-grow:1">所在文章&nbsp;:&nbsp;<%- audit.produceArticle.title %></a><span>
            <% if (audit.path === '' || audit.path === '0'){ %>
            <button onclick="forbit('<%- audit.produceArticle._id %>')" <% if (audit.produceArticle.status===1){ %>style="color:red"<% } %> /><i class="fa fa-ban"></i></button>
            <% }else{ %>
            <button onclick="delcom('<%- audit.produceArticle._id %>','<%- audit.path %>')" />×</button>
            <% } %>
        </span></p>
    </div>
    <% } %>
</div>
<script>
function forbit(id){
    postRequest('./deleteSomething', {col:'article',type:'forbid',filter:'{"_id":"'+id+'"}'});
}
function delcom(id, path){
    $.post( './comment', {article_id:id,basepath:path,brief:'{[REMOVE]}'}, (data, textStatus, jqXHR) => {
        if (!data.success) {
            showMessage('删除评论失败');
        }else{
            location.reload();
        }
    });
}
var types = [];
document.body.onload = function(){
    let typeChecks = document.querySelectorAll('.article-list>div:first-child>span>input[type="checkbox"]');
    let cols = window.getUrlParam('cols');
    if (cols != null){
        types = cols.split(',');
        typeChecks.forEach(check=>{
            if (types.indexOf(check.value)<0)
                check.checked = false;
        });
    }
    typeChecks.forEach(p=>{
        p.onchange = function(e){
            let cols='';
            typeChecks.forEach(check=>{cols += check.checked ? (check.value + ',') : ''});
            if (cols[cols.length-1] === ',')
                cols = cols.substr(0, cols.length-1);
            window.location.href = './publishaudit.html?cols='+cols;
        }
    });

    var socket=io.connect((window.useSSL ? "wss" : "ws") + "://"+window.location.hostname+":" + window.wsPort);
    socket.emit('signin', {user:window.user, channel:'publishaudit'});
    socket.on('newitem',handleNewItem);
};
var typemap = {article: '文章', comment: '评论', accusation: '举报', feedback: '反馈', advise: '建议'};
var subtypemap = {article: 'article', comment: 'comment', accusation: 'feedback', feedback: 'feedback', advise: 'feedback'};
function handleNewItem(audit) {
    if (('<%- blockRoot %>' === '' || audit.produceArticle.mainclass.match(/^<%- blockRoot %>(\/.*)?$/)) && types.indexOf(subtypemap[audit.types])>=0){
        let div = '<div>' +
            '<p><span class="time-span">' + audit.produceTime + '</span>&emsp;<a href="./user?id=' + audit.produceUser._id + '">' + audit.produceUser.nickname + '(' + audit.produceUser._id + ')' + '</a>&emsp;' + '发布/编辑的&nbsp;' + typemap[audit.type] + '</p>' +
            '<p>' + audit.brief + '</p>' +
            '<p class="adapt-panel"><a href="/' + audit.produceArticle.mainclass + '/article?id=' + audit.produceArticle._id+ '&path=' + audit.path + '" style="flex-grow:1">所在文章&nbsp;:&nbsp;' + audit.produceArticle.title + '</a><span>';
        if (audit.path === '' || audit.path === '0') {
            div += '<button onclick="forbit(\'' + audit.produceArticle._id + '\')" ' + (audit.produceArticle.status === 1 ? 'style="color:red"' : '') + ' ><i class="fa fa-ban"></i></button>';
        } else {
            div += '<button onclick="delcom(\'' + audit.produceArticle._id + '\',\'' + audit.path + '\')" >×</button>';
        }
        div += '</span></p></div>';



        $('.article-list>div:first-child').after(div);
    }
}
</script>
</body>
</html>